<template>
  <div class="com-select-sex">
    <el-select
      v-model="value"
      clearable
      placeholder="请选择"
      size="small"
      @change="hundelChange"
    >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      ></el-option>
    </el-select>
  </div>
</template>

<script>
import { isNull } from '@/utils/tool.js'
export default {
  props: {
    sex: {
      type: String,
    },
  },
  created() {
    this.value = this.sex
  },
  watch: {
    sex: {
      handler(val) {
        if (!isNull(val)) {
          this.value = null
        }
      },
    },
  },
  data() {
    return {
      value: null,
      options: [
        { value: 'MALE', label: '男' },
        { value: 'FEMALE', label: '女' },
        { value: 'UNKNOWN', label: '未知' },
      ],
    }
  },
  methods: {
    hundelChange(data) {
      this.$emit('update:sex', data)
    },
  },
}
</script>

<style></style>
